#!/bin/bash

echo "===start to upload tags==="
chmod +x scripts/common_scripts/common.sh
source scripts/common_scripts/common.sh

# env: gitcode_domain
function work() {
  echo "1. prepare env"
  pip3 install -r scripts/publish_pipeline/publish_by_comment/requirements.txt
  ret=$(python3 scripts/utils/prepare-env.py --gitcode_domain="${gitcode_domain}")
  package=$(echo $ret | jq -r '.package')

  echo "2. create tag"
  json_file="$package/mds/service.json"
  version=$(jq -r '.version' "$json_file")
  if [ -z "$version" ]; then
    echo "未找到版本号"
    exit 1
  fi
  echo "find the version: ${version}"
  python3 scripts/publish_pipeline/publish_by_comment/publish-tag.py --tag="${version}" --gitcode_token="${gitcode_token}"
}

function main() {
  prepare_software
  prepare_git $gitcode_username $gitcode_token
  work
}

main
